feat(schedule): 일정에 소유자를 저장한다 - #37
Merged
Merged
Conversation
Spring 이 검증한 액세스 토큰에서 꺼낸 사용자 ID 를 X-Auth-User-Id 헤더로 보낸다. 이를 schedules.user_id 에 저장한다. 없으면 내 일정 목록, 수정 권한, 공유가 성립하지 않는다. 헤더는 Spring 과의 내부 호출에만 쓴다. 외부에서 들어오는 값이 아니라 검증된 토큰에서 꺼낸 것이고, 두 컨테이너는 같은 도커 네트워크에 있으며 이 서버는 외부에 공개되지 않는다. 헤더가 없으면 소유자 없는 일정으로 저장한다. Spring 이 아직 인가를 켜지 않아 비로그인 생성이 가능하다. 소유자는 한 번 정해지면 바꾸지 않는다. save_schedule 은 ON CONFLICT DO UPDATE 라 일정 수정에서도 실행되는데, 수정 요청에는 소유자가 실리지 않는다. 그대로 덮으면 첫 수정에서 주인이 사라진다. COALESCE 로 기존 값을 유지한다. 컬럼은 Spring 의 V10 migration 이 만든다. 그쪽을 먼저 배포해야 한다. 순서가 바뀌면 없는 컬럼에 INSERT 해서 일정 생성이 전부 실패한다. 로컬에서 Spring 과 함께 띄워 확인했다. 로그인 상태로 만든 일정에 user_id 가 저장되고, 소유자 헤더가 없는 수정 요청 뒤에도 값이 유지되며, 비로그인 생성은 NULL 로 남는다. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spring 이 검증한 토큰에서 꺼낸 사용자 ID 를 받아
schedules.user_id에 저장한다.배경
지금 일정에는 주인이 없다.
GET /schedules가 전체 사용자의 일정을 반환하고, 남의 일정을수정하는 것도 막을 수 없다. Spring 에 인증이 붙으면서 소유자를 기록할 수 있게 됐다.
변경
app.pyX-Auth-User-Id헤더를 받아create_schedule로 넘긴다schedule/service.pyowner_id를save_schedule로 전달한다schedule/persistence.pyINSERT에user_id를 담는다판단한 것
헤더는 내부 호출 전용이다. 외부에서 들어오는 값이 아니라 Spring 이 액세스 토큰을 검증해
꺼낸 것이다. 두 컨테이너는 같은 도커 네트워크에 있고 이 서버는 외부에 공개되지 않는다.
커뮤니티가 쓰는 공개
X-User-Id와 헷갈리지 않도록 이름을 달리 했다.헤더가 없으면 소유자 없는 일정으로 저장한다. Spring 이 아직 인가를 켜지 않아 비로그인
생성이 가능하다.
소유자는 한 번 정해지면 바꾸지 않는다.
save_schedule은ON CONFLICT DO UPDATE라 일정 수정에서도 실행된다. 수정 요청에는소유자가 실리지 않으므로, 그대로 덮으면 첫 수정에서 주인이 사라진다.
배포 순서
Spring 의 #81 을 먼저 배포해야 한다.
schedules.user_id컬럼은 그쪽 V10 migration 이 만든다. 순서가 바뀌면 없는 컬럼에 INSERT 해서일정 생성이 전부 실패한다.
검증
로컬에 Spring 과 함께 띄워 확인했다.
user_id저장됨user_id유지됨user_idNULL🤖 Generated with Claude Code